package com.fanshuai.jmx.agent;

import com.fanshuai.jmx.mbean.Hello;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

public class JMXAgent {
    public static void init() throws Exception {
        /**
         * MBeanServer，JMX容器，默认提供JMX Agent，通过JConsole访问
         */
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

        /**
         * ObjectName  MBean名称表示
         * Domain:type=typename,name=xxx
         */
        ObjectName objectName = new ObjectName("custom:name=hello");
        Hello hello = new Hello();
        hello.setAge(10);
        hello.setName("test");
        mBeanServer.registerMBean(hello, objectName);
    }
}
